﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

namespace MVC4Shop.Models
{
    public class ShoppingCartModel
    {
        private Hashtable arr;
        public ShoppingCartModel()
        {
            arr = new Hashtable();
        }

        public void AddToCart(string id,CartModel cart)
        {
            if (!arr.ContainsKey(id))
                arr.Add(id, cart);
            else
                arr[id] = cart;
        }

        public void RemoveFromCart(string id)
        {
            if(arr.ContainsKey(id))
                arr.Remove(id);
        }

        public void EmptyCart()
        {
            arr.Clear();
        }

        public List<CartModel> GetProduct()
        {
            return arr.Values.Cast<CartModel>().ToList();
        }

        public int GetCount()
        {
            return arr.Count;
        }
    }
}